<?php 
/**
 * Web Request 
 * This class manages web request
 * 
 * @package    Lazy Framework
 * @subpackage request
 * @author     Eduardo Marcolino <eduardo.marcolino@gmail.com>
 * @copyright  (c) 2010 Eduardo Marcolino <eduardo.marcolino@gmail.com>
 */

class WebRequest implements Request
{
	public 
		$params = null,
		$files  = null;
	
	public function __construct($request,$files)
	{
		$this->params = $request;
		$this->files  = $files;	
	}
	
	public function isMultiPartRequest(){
		if (isset( $_SERVER['CONTENT_TYPE'])) 
		{
			return preg_match('/^multipart/', $_SERVER['CONTENT_TYPE']);
		}
		return false;
	}
	public function isXmlHttpRequest(){
		//TODO Implementing ajax request check
	}
	public function hasFiles() {
		return (sizeof($_FILES) > 0);
	}
	public function getFileNames(){
		return array_keys($_FILES);
	}
	/**
	 * Return a UploadFile component
	 * @param String $key Key of file
	 * @return UploadedFile $file
	 */
    public function getFile($key) {
        return new UploadedFile($this->files[$key]);
    }
	public function hasParameter($key){
		return array_key_exists($key,$this->params);
	}
	public function getParameter($key){
		return $this->hasParameter($key) ? $this->params[$key] : null;
	}
}
?>